package com.carsystems.controller;

import com.carsystems.mapper.StatueScoureMapper;
import com.carsystems.pojo.StatueScoure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StatueScoureController {
    @Autowired
    private StatueScoureMapper statueScoureMapper;

    //查询全部
    @GetMapping("/statueList")
    public List<StatueScoure> StatueList(){
        List<StatueScoure> statueScoures = statueScoureMapper.StatueList();
        return statueScoures;
    }
//按id查询扣分项
    @GetMapping("/getscoureid")
    public StatueScoure getscoureid(Integer scoure_id){
        return statueScoureMapper.selectByPrimaryKey(scoure_id);
    }
//增加一个扣分项
   @ResponseBody
    @PostMapping("/addStatue")
    public String addStatue(@RequestBody StatueScoure statue){
        statueScoureMapper.addStatue(statue);
        if (statue != null){
            return "success";
        }else {
            return "fail";
        }
}

//修改扣分项信息
    @ResponseBody
    @PostMapping("/updateStatue")
    public String updateStatue(@RequestBody StatueScoure statue){
       int row=  statueScoureMapper.updateStatue(statue);
       statueScoureMapper.selectByPrimaryKey(statue.getScoure_id());
        if (row == 1){
            return "success";
        }else {
            return "fail";
        }
    }

    //删除一个扣分项
    @ResponseBody
    @GetMapping("/deleStatue")
    public String deleStatue(@RequestBody StatueScoure statueid){
        int row=  statueScoureMapper.daleteStatue(statueid.getScoure_id());
        if (row == 1){
            return "success";
        }else {
            return "fail";
        }
    }
}
